﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JqueryNet.FormControl.FormHtmlControl
{
    public class JHtmlInputCheckBox : JHtmlControl
    {
        private System.Web.UI.HtmlControls.HtmlInputCheckBox htmlInputCheckBox;

        public JHtmlInputCheckBox(System.Web.UI.HtmlControls.HtmlInputCheckBox htmlInputCheckBox):base(htmlInputCheckBox)
        {
            // TODO: Complete member initialization
            this.htmlInputCheckBox = htmlInputCheckBox;             
        }

        public override void Attr(string key)
        {
            if (key.ToLower() == "checked")
            {
                Value = htmlInputCheckBox.Checked;
            }
            else
            {
                base.Attr(key);
            }            
        }

        public override void Attr(string key, string value)
        {
            bool f;
            bool.TryParse(value, out f);
            if (key.ToLower() == "checked")
            {
                htmlInputCheckBox.Checked = f;
            }
            else
            {
                base.Attr(key, value);
            }
        }

        public override void Val()
        {            
            Value = htmlInputCheckBox.Value;
        }

        public override void Val(string value)
        {
            htmlInputCheckBox.Value = value;            
        }
    }
}
